package db.day06;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @Author Gan
 * @Date 2021/5/27 20:02
 * @Description:
 */
public class DruidUtils {

    static DataSource dataSource;

    static {

        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream("druid.properties"));

            dataSource = DruidDataSourceFactory.createDataSource(properties);


        }  catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection(){

        Connection connection = null;
        try {
            connection = dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return connection;
    }

    public static DataSource getDataSource(){

        return dataSource;
    }
}
